All Questions
31 questions
1vote
0answers
138views
Making Robert Tarjan's offline LCA algorithm run (much) faster (Java)
I have produced this GitHub repository that compares the performance of: Robert Tarjan's off-line lowest common ancestors algorithm, An improvement of the above algorithm. Typical demo program ...
1vote
2answers
116views
Circular list vs. doubly-linked list: which is faster?
In this post, I will compare performance of a circular list and a conventional list with head/tail -references: ...
2votes
2answers
866views
Counting uppercase and lowercase characters in a string
I created two programs (one with JAVA8) to calculate the total count of uppercase and lowercase characters in given String. After checking the execution time JAVA8 is taking longer execution time than ...
2votes
3answers
3kviews
Classifying integers as "weird" or "not weird"
Problem Statement Given an integer N, perform the following conditional actions: If N is odd, print Weird If N is even and in the inclusive range of 2 to 5, print Not Weird If N is even ...
3votes
1answer
102views
Most efficient way to check if user is allowed to update an object
So I have an user which can create his own Locations. I implemented a webservice in order to add and update locations. If the user is not the owner of the location i want to throw an appropriate ...
5votes
1answer
620views
Two ways of implementing a combat system
Below is a segment of a game I am writing to stay in practice with my Java. EDIT The class this method is in is the Encounter class. This class just manages the encounter between the player and an ...
3votes
3answers
221views
String comparator as a lambda
I am writing a Comparator for my TreeMap. It looks like this: ...
1vote
3answers
2kviews
Merge sorted lists, removing duplicates
I want to merge two sorted lists of Integers but this is not the general mergesort case because the same number may appear in both lists. (However, each number can only appear once in a particular ...
2votes
1answer
581views
check for null before or after casting
I have a list of BasicDBObject that I fetch from my database. This is basically a JSON document converted into a java Object. Let's assume that we have a ...
0votes
1answer
596views
Foreach vs Iterator [closed]
I have implemented a trim method which removes objects having empty properties. This list has average size of 3 or so. Probably, the max length is 7 or 8. I ...
0votes
1answer
4kviews
Remove null + empty + duplicate elements in arraylist of string
I am looking for the best and fast way(performance wise) to remove null, empty and duplicate elements in arraylist of string. This method can be called maximum 700 times and the list can contains ...
4votes
3answers
3kviews
Dijkstra's algorithm using priority queue running slower than without PQ
I need to implement dijkstra's algorithm and I've done so using this Wikipedia page. I've done it both with priority queue and without. Both versions work 100% correct, however I need the faster one ...
0votes
1answer
73views
Finding the array indices of three specific headers
I'm considering how to refactor code to make it clean & clear. There are some principles to make code clean; in this case I think it's Single Responsibility and One level of abstraction. The ...
4votes
1answer
265views
Comparing three data structures for dealing with probability distributions in Java
Introduction Suppose you are given three elements \$a, b, c\$ with respective weights \$1, 1, 3\$. Now, a probability distribution data structures will return upon request \$a\$ with probability 20%, ...
1vote
1answer
152views
Sort by year and day descending, yet time ascending
I recently discovered a hugely inefficient portion of code in my program, and have gone about rewriting it. I am however, not quite sure if the rewritten program actually does exactly what I want, due ...